//
//  GYXNavigationController.swift
//  GYXWeibo
//
//  Created by Twisal on 2016/11/8.
//  Copyright © 2016年 Twisal. All rights reserved.
//

import UIKit

class GYXNavigationController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()
        navigationBar.isHidden = true
    }
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        print(viewController)
        if childViewControllers.count > 0 {
            viewController.hidesBottomBarWhenPushed = true
            
            if let vc = viewController as? GYXBaseViewController {
                var title = "返回"
                if childViewControllers.count == 1 {
                    title = childViewControllers.first?.title ?? "返回"
                }
                vc.naviItem.leftBarButtonItem = UIBarButtonItem(title: title, target: self, action: #selector(popToParentVc), isBack: true)
            }
        }
        super.pushViewController(viewController, animated: true)
    }
    
    @objc fileprivate func popToParentVc() {
        popViewController(animated: true)
    }
}
